package network

import (
	"fmt"
	"github.com/go-playground/validator/v10"
	"github.com/golang/protobuf/proto"
)

// protobuf枚举自定义校验器
func EnumValidator(packageName string) func(fl validator.FieldLevel) bool {
	return func(fl validator.FieldLevel) bool {
		enumValueMap := proto.EnumValueMap(fmt.Sprintf("%s.%s", packageName, fl.Field().Type().Name()))
		if _, ok := enumValueMap[fmt.Sprintf("%s", fl.Field().Interface())]; ok {
			return true
		} else {
			return false
		}
	}
}
